

package ImageFileSelector;

import java.io.File;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.filechooser.FileView;


public class ImageFileView extends FileView {
    ImageIcon jpgIcon = ImageUtils.createImageIcon("/resources/images/jpegIcon.jpg");
    ImageIcon gifIcon = ImageUtils.createImageIcon("/resources/images/gifIcon.jpg");
    ImageIcon tiffIcon = ImageUtils.createImageIcon("/resources/images/tiffIcon.jpg");
    ImageIcon pngIcon = ImageUtils.createImageIcon("/resources/images/pngIcon.jpg");

    @Override
    public String getName(File f) {
        return null; //let the L&F FileView figure this out
    }

    @Override
    public String getDescription(File f) {
        return null; //let the L&F FileView figure this out
    }

    @Override
    public Boolean isTraversable(File f) {
        return null; //let the L&F FileView figure this out
    }

    @Override
    public String getTypeDescription(File f) {
        String extension = ImageUtils.getExtension(f);
        String type = null;

        if (extension != null) {
            switch (extension) {
                case ImageUtils.jpeg:
                case ImageUtils.jpg:
                    type = "JPEG Image";
                    break;
                case ImageUtils.gif:
                    type = "GIF Image";
                    break;
                case ImageUtils.tiff:
                case ImageUtils.tif:
                    type = "TIFF Image";
                    break;
                case ImageUtils.png:
                    type = "PNG Image";
                    break;
            }
        }
        return type;
    }

    @Override
    public Icon getIcon(File f) {
        String extension = ImageUtils.getExtension(f);
        Icon icon = null;

        if (extension != null) {
            switch (extension) {
                case ImageUtils.jpeg:
                case ImageUtils.jpg:
                    icon = jpgIcon;
                    break;
                case ImageUtils.gif:
                    icon = gifIcon;
                    break;
                case ImageUtils.tiff:
                case ImageUtils.tif:
                    icon = tiffIcon;
                    break;
                case ImageUtils.png:
                    icon = pngIcon;
                    break;
            }
        }
        return icon;
    }
}
